package com.kun.video.controller;

import com.kun.video.domain.StageSize;
import com.kun.video.ui.window.VideoButtonView;
import com.kun.video.ui.window.VideoToVideoButtonDataContext;
import com.kun.video.ui.window.VideoView;
import com.kun.video.util.ComUtil;
import javafx.fxml.FXML;
import javafx.scene.image.Image;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;

/**
 * TODO
 *
 * @author gzc
 * @since 2025/3/9 17:56
 **/
public class HomeController extends AbstractController {
    private static final Logger log = LoggerFactory.getLogger(HomeController.class);

    private static final BigDecimal VIDEO_PLAY_BOX_RATIO = BigDecimal.valueOf(0.7D);
    private static final BigDecimal BUTTON_BOX_RATIO = BigDecimal.valueOf(0.3D);
    @FXML
    public VideoView videoView;
    @FXML
    public VideoButtonView videoButtonView;

    @Override
    protected StageSize getMainStageSize() {
        return new StageSize(1400, 1000,
                1300, 800,
                ComUtil.DIMENSION.getWidth(), ComUtil.DIMENSION.getHeight());
    }

    @Override
    protected void reactiveDimensions(Double width, Double height) {
        if (width != null) {
            double width1 = new BigDecimal(width).multiply(VIDEO_PLAY_BOX_RATIO).doubleValue();
            videoView.setPrefWidth(width1);
            videoView.setMaxWidth(width1);
            double width2 = new BigDecimal(width).multiply(BUTTON_BOX_RATIO).doubleValue();
            videoButtonView.setPrefWidth(width2);
            videoButtonView.setMaxWidth(width2);
        }
        if (height != null) {
            videoView.setPrefHeight(height);
            videoView.setMaxHeight(height);
            videoButtonView.setPrefHeight(height);
            videoButtonView.setMaxHeight(height);
        }
    }

    @Override
    protected void initLayout() {
    }

    @Override
    protected void initData() {
        stage.getIcons().add(new Image("/icon.png"));
        new VideoToVideoButtonDataContext(videoView, videoButtonView);
//        videoView.setMedia("E:\\成品\\猫\\抽象配音小猫咪3\\抽象配音小猫咪3-1.mp4");
    }

    @Override
    public void stopCallback() {
        videoView.dispose();
    }
}
